package com.abc.example.enumeration;

import com.abc.example.exception.BaseException;
import com.abc.example.exception.ExceptionCodes;

/**
 * @className	: EDeleteFlag
 * @description	: 记录删除标记
 * @summary		:
 * @history		:
 * ------------------------------------------------------------------------------
 * date			version		modifier		remarks                   
 * ------------------------------------------------------------------------------
 * 2023/05/17	1.0.0		sheng.zheng		初版
 *
 */
public enum EDeleteFlag {
    dfValidE	(0,"正常"),
    dfDeletedE	(1,"已删除"),
	;	// 结束定义
	
	// 枚举值对应的code值
	int code;
	
	// 描述
	String desc;

	// 构造函数
	private EDeleteFlag(int code,String desc) {
	    this.code = code;
	    this.desc = desc;
	}

	// 属性code的getter方法
	public int getCode() {
	    return code;
	}

	// 属性code的setter方法
	public void setCode(int code) {
	    this.code = code;
	}
	
	// desc的getter/setter方法
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	
	/**
	 * 
	 * @methodName	: getType
	 * @description	: 根据code获取枚举值
	 * @param code	: code值 
	 * @return		: code对应的枚举值
	 * @history		:
	 * ------------------------------------------------------------------------------
	 * date			version		modifier		remarks                   
	 * ------------------------------------------------------------------------------
	 * 2023/05/17	1.0.0		sheng.zheng		初版
	 *
	 */
	public static EDeleteFlag getType(int code) {
		// 返回值变量
		EDeleteFlag eRet = null;
		
		for (EDeleteFlag item : values()) {
			// 遍历每个枚举值
			if (code == item.getCode()) {
				// code匹配
				eRet = item;
				break;
			}
		}
		
		return eRet;
	}

	// 检查并获取指定code的枚举值
	public static EDeleteFlag getTypeByCode(int code) {
		EDeleteFlag item = getType(code);
		if (item == null) {
			throw new BaseException(ExceptionCodes.INVALID_ENUM_VALUE,"EDeleteFlag with code="+code);
		}
		
		return item;
	}	
}